<template>
  <div class="user">
      <div class="head" v-if="token">
        <img :src="userInfo.avatar" alt="">
        <div class="content">
          <div class="name">{{userInfo.nickname}}</div>
          <div class="type">微信用户</div>
        </div>
        <van-icon name="arrow" @click="toExit" />
      </div>
      <div class="head" v-else>
        <img :src="avater" alt="">
        <div class="content">
          <div class="name">未获取用户信息,请先登陆</div>
          <!-- <div class="type">微信用户</div> -->
        </div>
        <van-icon name="arrow" @click="toRegister" />
      </div>
      <div class="link">
        <div class="link-item" v-for="(item,index) in structure" :key="index">
          <div class="imgBox">
            <img :src="item.icon" alt="">
          </div>
          <div class="linkname">{{item.title}}</div>
        </div>
      </div>
  </div>
</template>

<script>
export default {
    name:"User",
    data(){
      return{
        userInfo:{},
        token:'',
        avater:require('@/assets/img/avater.jpg'),
        structure:[
          {
            title: "我的订单",
            icon:require('@/assets/icons/dingdan.png'),
            url: "/pages/order/main"
          },
          {
            title: "优惠券",
            icon: require('@/assets/icons/youhuiquanwenzi.png'),
            url: ""
          },
          {
            title: "我的足迹",
            icon:require('@/assets/icons/wodezuji.png'),
            url: ""
          },
          {
            title: "我的收藏",
            icon:require('@/assets/icons/shoucang.png'),
            url: "/pages/collectlist/main"
          },
          {
            title: "地址管理",
            icon:require('@/assets/icons/dizhi.png'),
            url: "/pages/addrManager/main"
          },
          {
            title: "联系客服",
            icon:require('@/assets/icons/fuwu.png'),
            url: ""
          },
          {
            title: "帮助中心",
            icon:require('@/assets/icons/wenti.png'),
            url: ""
          },
          {
            title: "意见反馈",
            icon:require('@/assets/icons/pinglun.png'),
            url: "/pages/feedback/main"
          }
       ]
      }
    },
    methods:{
      // 跳到登陆页面
      toRegister(){
        this.$router.push('/register')
      },
      // 退出登陆
      toExit(){
        this.$dialog.confirm({
          message:'是否退出',
          title:'更改状态',
          beforClose:this.beforClose
          }).then(res =>{
            this.$token.removeToken('token')
            this.$token.removeToken('userInfo')
            this.token = ''
            this.userInfo = ''
          }).catch(err =>{
            

          })
         
      },
     
    },
    mounted(){
      this.token = sessionStorage.getItem('token')
      this.userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
    }
}
</script>

<style lang="less" scoped>
@import './index.less';

</style>